package it.tempogara.tgsender;

import it.tempogara.tgsender.R;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.InputType;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

public class SettingsActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_settings);
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
		
		EditText edIp = (EditText) findViewById(R.id.editTextIP);
		edIp.setText(prefs.getString("IP", "192.168.10.20"));
		final EditText edAdd = (EditText) findViewById(R.id.editTextAddress);
		edAdd.setText(prefs.getString("Address", "www.tempogara.it"));
		EditText edEmail = (EditText) findViewById(R.id.EditTextEmail);
		edEmail.setText(prefs.getString("AddressEmail", "info@tempogara.it"));
		EditText edPass = (EditText) findViewById(R.id.editTextPass);
		edPass.setText(prefs.getString("Passw", "bgqa4uos"));
		EditText edUser = (EditText) findViewById(R.id.editTextUser);
		edUser.setText(prefs.getString("User", "1843848@aruba.it"));
		EditText edNumber = (EditText) findViewById(R.id.editTextNumber);
		edNumber.setText(prefs.getString("Number", "5"));
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.settings, menu);
		return true;
	}
	
	public void save(View v){
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
		Editor prefsEditor = prefs.edit();
		EditText edIp = (EditText) findViewById(R.id.editTextIP);
		prefsEditor.putString("IP", edIp.getText().toString());
		final EditText edAdd = (EditText) findViewById(R.id.editTextAddress);
		if(!edAdd.getText().toString().equals(""))
			prefsEditor.putString("Address", edAdd.getText().toString());
		final EditText edEmail = (EditText) findViewById(R.id.EditTextEmail);
		if(!edEmail.getText().toString().equals(""))
			prefsEditor.putString("AddressEmail", edEmail.getText().toString());
		EditText edUser = (EditText) findViewById(R.id.editTextUser);
		if(!edUser.getText().toString().equals(""))
			prefsEditor.putString("User", edUser.getText().toString());
		EditText edPass = (EditText) findViewById(R.id.editTextPass);
		if(!edPass.getText().toString().equals(""))
			prefsEditor.putString("Passw", edPass.getText().toString());
		EditText edNumber = (EditText) findViewById(R.id.editTextNumber);
		if(!edNumber.getText().toString().equals(""))
			prefsEditor.putString("Number", edNumber.getText().toString());

		prefsEditor.commit();
		ApplicationData appData = (ApplicationData) getApplication();
		finish();
	}

}
